﻿CREATE VIEW [dbo].[ASMS_V_MaintenanceBillMaterial]
	AS 
SELECT MBM.*,
	M.Name as MaterialName,
	MRB.WarehouseId as ActualWarehouseId,
	MRB.HandledTime as ActualFinishedTime,
	MRB.Handler as ActualHandlerId,
	S.Name as ActualHandlerName,
	MRB.Status as ActualStatus,
	W.Name  as ActualWarehouseName,
	S2.Name as SalesManagerName,
	MRB.Id as MaterialRequisitionBillId
FROM ASMS_MaintenanceBillMaterial as MBM
	left join ASMS_MaterialRequisitionBill as MRB on MRB.MaintenanceBillMaterialId = MBM.Id and MRB.[Status] = 1
	left join ASMS_Warehouse as W on W.Id = MRB.WarehouseId
	left join ASMS_Material as M on M.Id = MBM.MaterialId
	left join ASMS_Staff as S on S.Id = MRB.Handler
	left join ASMS_Staff as S2 on S2.Id = MBM.SalesManagerId

